package com.ruiysoft.service.order.util;

import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * Date : 2018-05-28
 *
 * @author WenJialu
 */
//@Component
public class RedisHandle {

	@Resource
	RedisTemplate<String, String> redisStringTmpl;


	public String stringGet(String key){
		return redisStringTmpl.opsForValue().get(key);
	}

	public void stringSet(String key, String value){
		redisStringTmpl.opsForValue().set(key, value);
	}

	public String hashGet(String key, String field){
		Object obj = redisStringTmpl.opsForHash().get(key, field);
		return null == obj ? null : obj.toString();
	}

	public void hashSet(String key, String field, String value){
		redisStringTmpl.opsForHash().put(key, field, value);
	}

	public void delete(String key){
		redisStringTmpl.delete(key);
	}

	public void hashDelete(String key, String... fields){
		if (null != fields && 0 < fields.length) {
			redisStringTmpl.opsForHash().delete(key, fields);
		}
	}

}
